<?php
/*
 * @Description    : 
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2019-11-12 22:03:19
 * @LastEditors    : QianLong
 * @LastEditTime   : 2020-12-28 11:52:10
 */

declare(strict_types=1);

namespace App\Exception;

use App\Constants\Status;
use Hyperf\Server\Exception\ServerException;
use Throwable;

class ApiException extends ServerException
{
    public function __construct(int $code = 0, $message = null, Throwable $previous = null)
    {
        if (is_null($message)) {
            $message = Status::getMessage($code,['']);
        }
        if ($code == 1012) {
            $message = Status::getMessage($code,['']).','.$message;
        }
        if (is_array($message)) {
            $message = implode(';',$message);
        }
        if (!$message) {
            $message = 'unknown';
        }
        $requestId = createId('RFE');
        requestFailLog(['code'=>$code,'msg'=>$message],$requestId);
        parent::__construct($message.' RequestId：'.$requestId, $code, $previous);
    }
}
